#include<iostream>
#include"Comm.hpp"
#include<string.h>
//记录发现命名管道的两个特点：
//1. 当写端未打开，读端open一直阻塞
//2. 当写端关闭，读端也会自动关闭
using namespace std;
int main()
{
  int wfd  = open(Path, O_WRONLY);
  if(wfd < 0)
  {
    cerr<< "open failed errono: " << errno << ", errstring:"<< strerror(errno) <<endl;
    return 1;
  }
  string buffer;
  while(true)
  {
    cout << "Please Enter Your Message# ";
    std::getline(cin,buffer);
    if(buffer == "quit") break;
    ssize_t n = write(wfd,buffer.c_str(),buffer.size());//向命名管道写入
    if(n < 0)
    {
      cerr << "write failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
      break;
    }
  }
  close(wfd);
  return 0;
}
